import cloneDeep from 'lodash/cloneDeep'
const state = () => ({
  actionsData: {}, // 动作执行过程中数据
  eventData: {}, // 当前事件的数据
})

const getters = {
  getActionsData(state) {
    return state.actionsData
  },
  getEventData(state) {
    return state.eventData
  },
}

const mutations = {
  setActionsData(state, { moduleId, actionId, actionData }) {
    console.log('设置动作值 ---------------- ', moduleId, actionId, actionData)
    if (!state.actionsData[moduleId]) state.actionsData[moduleId] = {}
    state.actionsData[moduleId][actionId] = cloneDeep(actionData)
  },
  delActionsData(state, moduleId) {
    delete state.actionsData[moduleId]
  },
  setEventData(state, val) {
    state.eventData = val
  },
}

const actions = {
  setActionsData({ commit }, val) {
    commit('setActionsData', val)
  },
  delActionsData({ commit }, val) {
    commit('delActionsData', val)
  },
  setEventData({ commit }, val) {
    commit('setEventData', val)
  },
}

export default {
  state,
  getters,
  mutations,
  actions,
}
